﻿using System;

namespace StreakyDownloader.Model
{
   /// <summary>
   /// Passive object for storing information about a file to download 
   /// including the actual filename, the ID of the file to download as 
   /// well as some download status information.
   /// </summary>
   public class DownloadFile
   {
      /// <summary>
      /// keeps track if the file has been downloaded or not.
      /// </summary>
      protected bool m_downloaded;

      /// <summary>
      /// set if the user cancelled this file downloading.
      /// </summary>
      protected bool m_userCancelled;

      /// <summary>
      /// keeps track if any error occurred during the download.
      /// </summary>
      protected bool m_errorOccurred;

      /// <summary>
      /// the exception that occured during the download of this file.  Null if no
      /// error occurred.
      /// </summary>
      protected Exception m_error;

      /// <summary>
      /// The ID representing the file on the download store.
      /// </summary>
      protected string m_fileID;

      /// <summary>
      /// The actual filename of the file to download.
      /// </summary>
      protected string m_filename;

      #region Properties
      public string FileID
      {
         get { return m_fileID; }
      }

      public string Filename
      {
         get { return m_filename; }
         set { m_filename = value; }
      }

      public bool UserCancelled
      {
         get { return m_userCancelled; }
         set 
         {
            if (true == value)
            {
               m_downloaded = false;
            }

            m_userCancelled = value; 
         }
      }

      public bool ErrorOccurred
      {
         get { return m_errorOccurred; }
         set 
         {
            if (true == value)
            {
               m_downloaded = false;
               m_userCancelled = false;
            }

            m_errorOccurred = value; 
         }
      }

      public Exception Error
      {
         get { return m_error; }
         set { m_error = value; }
      }

      public bool Downloaded
      {
         get { return m_downloaded; }
         set 
         {
            if (true == value)
            {
               m_userCancelled = false;
               m_errorOccurred = false;
               m_error = null;
            }

            m_downloaded = value; 
         }
      }
      #endregion

      /// <summary>
      /// Create the download file with the specified file ID.
      /// Most likely this is the ID that represents the file from
      /// the source where it is downloaded from.
      /// </summary>
      /// <param name="ID">Unique identifier for the file to download.</param>
      public DownloadFile(string ID)
      {
         m_downloaded = false;

         m_userCancelled = false;
         m_errorOccurred = false;
         m_error = null;

         m_filename = string.Empty;
         m_fileID = ID;
      }
   }
}
